package com.lej.core.utils

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.text.TextUtils
import com.lej.core.base.app

/*** 文本复制功能*/
fun CharSequence?.copyToClip(label: CharSequence? = null) {
    if (TextUtils.isEmpty(this)) {
        return
    }
    val clipboard = app.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
    clipboard.setPrimaryClip(ClipData.newPlainText(label, this))
}

/**获取app名字*/
fun Context.getAppName() = kotlin.runCatching {
    val packageManager = this.packageManager
    val packageInfo = packageManager.getPackageInfo(this.packageName, 0)
    packageManager.getApplicationLabel(packageInfo.applicationInfo)
}.getOrNull()
